package com.motong.gongdan.config;

import com.mysql.cj.jdbc.exceptions.MysqlDataTruncation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import javax.servlet.http.HttpServletRequest;

@RestControllerAdvice
public class GlobalExceptionHandler {

    private static final Logger logger = LoggerFactory.getLogger(GlobalExceptionHandler.class);

    @ExceptionHandler(value = MysqlDataTruncation.class)
    @ResponseBody
    public ResponseData<String> exceptionHandler(HttpServletRequest httpServletRequest, MysqlDataTruncation e) {
        if (e.getMessage().contains("Data too long")) {
            return ResponseData.fail("数据长度溢出");
        }
        e.printStackTrace();
        return ResponseData.fail("网络波动，请稍后再试");
    }


}
